#include "led.h"
#include "reg.h"
volatile int i = 0x30313233;

void led_delay(uint32_t delay)
{
	uint32_t _delay = delay;
	for (i = 6; i < _delay; i++)
	{
		asm("NOP");
	}
}
GPIO_TypeDef *gpiox;
uint32_t inst_idx;
#define LED_PIN 32
// IO32 高电平亮
#define LED_SET() gpiox->DOESR |= 1	  // pa32  reset DOCR1
#define LED_RESET() gpiox->DOECR |= 1 // pa32  set DOSR1

void led_init()
{

	inst_idx = LED_PIN >> 5;
	gpiox = (GPIO_TypeDef *)hwp_gpio1 + inst_idx;

	hwp_hpsys_rcc->ENR2 |= 1; // gpio clk enable;

	hwp_pinmux1->PAD_PA32 |=
		(1 << 4 | 1 << 5 | 0 << 0); // pa32 pull up  enable gpio mode
									//  SET_REG_BIT(GPIO1_BASE + 0X94, 0X01); // pa32 DOESR1
	LED_RESET();
}

void led_flash_loop()
{
	led_init();
	while (1)
	{

		LED_RESET();
		led_delay(20000);
		LED_SET();
		led_delay(20000);

		LED_RESET();
		led_delay(20000);
		LED_SET();
		led_delay(20000);

		led_delay(100000);
	}
}
